package com.yeyks.hotel.utils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.yeyks.common.exception.ServiceException;

import java.util.Date;

public class HotelSearchUtil {

    public static void checkSearchDate(Date startDate, Date endDate) {
//        //时间修正
//        startDate = fixDate(startDate);
//        endDate = fixDate(endDate);
        //时间校验
        DateTime todayBegin = DateUtil.beginOfDay(new Date());
        DateTime tomorrowBegin = DateUtil.offsetDay(todayBegin, 1);
        DateTime ThirtyDaysLaterBegin = DateUtil.offsetDay(tomorrowBegin, 30);
        if (startDate.after(endDate)
                || startDate.before(todayBegin)
                || endDate.before(tomorrowBegin)
                || endDate.after(ThirtyDaysLaterBegin)) {
            throw new ServiceException("请求参数不正确");
        }
    }

//    private static final Date fixDateStart = new Date(120, 11, 24);

//    //临时修正时间参数
//    public static Date fixDate(Date date) {
//        if (CompareUtil.compare(fixDateStart, date) < 0) {
//            return DateUtil.offset(date, DateField.YEAR, -1).toJdkDate();
//        }
//        return date;
//    }

}
